package com.bocloud.cmp.service.app.monitor;

import java.util.concurrent.Callable;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.cmp.entity.app.resource.OpenshiftMonitor;
import com.bocloud.common.model.BaseResult;
/**
 * @author Zaney
 * @data:2017年4月20日
 * @describe:第一次线程池任务
 */
public class AppFirstTask implements Callable<BaseResult<JSONObject>> {
	
	private OpenshiftMonitor monitor;
	private AppFirstClient appFirstClient;
	private JSONArray labels;
	public AppFirstTask(OpenshiftMonitor monitor, JSONArray labels) {
		super();
		this.monitor = monitor;
		this.labels = labels;
		appFirstClient = new AppFirstClient();
		appFirstClient.setAppSecondClient(new AppSecondClient());
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public BaseResult<JSONObject> call() throws Exception {
		switch (monitor.getResourceType()) {
		case "cpu":
			JSONObject cpu = appFirstClient.cpu(monitor, labels);
			if (null == cpu) {
				return new BaseResult(false, "get monitor info error", null);
			}
			return new BaseResult(true, "success", cpu);
		case "memory":
			JSONObject memory = appFirstClient.memory(monitor, labels);
			if (null == memory) {
				return new BaseResult(false, "get monitor info error", null);
			}
			return new BaseResult(true, "success", memory);
		case "networkRx":
			JSONObject networkRx = appFirstClient.networkRx(monitor, labels);
			if (null == networkRx) {
				return new BaseResult(false, "get monitor info error", null);
			}
			return new BaseResult(true, "success", networkRx);
		default:
			JSONObject networkTx = appFirstClient.networkTx(monitor, labels);
			if (null == networkTx) {
				return new BaseResult(false, "get monitor info error", null);
			}
			return new BaseResult(true, "success", networkTx);
		}
	}

}
